package test.client;

import java.awt.Color;
import java.awt.Font;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JTextArea;

public class UserText extends JTextArea
{
	private static final long	serialVersionUID	= 1L;

	private Map<String, String>	users				= new HashMap<String, String>();

	public UserText() {
		this.setLineWrap(true);
		this.setEditable(false);
		this.setFont(new Font("微软雅黑",Font.BOLD,14));
		this.setForeground(new Color(255,0,255));
	}

	public void updateText() {
		StringBuilder bf = new StringBuilder(0);
		synchronized (users) {
			for (String s : users.values()) {
				bf.append(" " + s + "\r\n");
			}
		}
		setText(" " + bf.toString().trim());
	}

	public void addUser(String id, String name) {
		synchronized (users) {
			users.put(id ,name);
		}
	}

	public void removeUser(String id) {
		synchronized (users) {
			users.remove(id);
		}
	}

}
